<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('学生项目管理')"/>
    <th:block th:include="include :: select2-css"/>
    <th:block th:include="include :: bootstrap-select-css" />
    <th:block th:include="include :: datetimepicker-css" />
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="data-form">
                <input id="teacherId" name="teacherId"  th:value="*{teacherId}" hidden="true">
                <div class="select-list">
                    <ul>
                        <li>
                            <label>时间：</label>
                            <div class="input-group date">
                                <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                                <input type="text" class="col-sm-3 control-label" id="scheduleTime" placeholder="yyyy-MM-dd">
                                <label style="width: 25px"></label>
<!--                                <label shiro:hasPermission="education:schedule:searchTeacher">老师姓名：</label>-->
<!--                                <input shiro:hasPermission="education:schedule:searchTeacher" id="teacherName" type="text" class="col-sm-3 control-label '+searchTeacherFlag+'" name="teacherName" />-->
                                <label style="width: 25px"></label>
                                <label>学生姓名：</label>
                                <input id="childName" type="text" class="col-sm-3 control-label" name="childName" />
                                <label style="width: 25px"></label>
                                </label>课程名称：</label>
                                <select name="projectType"  th:with="type=${@dict.getType('business_project_type')}" style="margin-right: 25px">
                                    <option value="">全部</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                            </div>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table" data-auto-refresh-silent="true" data-auto-refresh ="false" data-auto-refresh-interval="5" ></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: bootstrap-table-auto-refresh-js" />
<th:block th:include="include :: select2-js"/>
<th:block th:include="include :: bootstrap-select-js" />
<th:block th:include="include :: datetimepicker-js" />
<script th:inline="javascript">
    var projectType = [[${@dict.getType('business_project_type')}]];
    // 权限
    var editFlag = [[${@permission.hasPermi('education:schedule:edit')}]];
    var newProgramEdit = [[${@permission.hasPermi('education:schedule:newProgramEdit')}]];

    // 字典
    var prefix = ctx + "education/schedule";

    $(function(){
        layui.use('laydate', function(){
            layui.laydate.render({
                elem: '#scheduleTime',
                value: new Date(),
                format: 'yyyy-MM',
                type: 'month'
            });
        })
    });

    $(function () {
        var options = {
            url: prefix + "/listByTeacherIdAndMonth",
            queryParams: queryParams,
            modalName: "数据",
            columns: [
                {
                    field: 'childName',
                    title: '学员姓名',
                },
                {
                    field: 'projectType',
                    title: '课程名称',
                    align: "center",
                    formatter: function (value, row, index) {
                        if ($.common.isNotEmpty(value)) {
                            return $.table.selectDictLabel(projectType, value);
                        } else {
                            return null;
                        }
                    }
                },
                // {
                //     field: 'teacherName',
                //     title: '老师姓名',
                // },
                {
                    field: 'confirm',
                    title: '项目生成状态',
                    align: "center",
                    formatter: function (value, row, index) {
                        var actions = [];
                        if ($.common.isNotEmpty(value)) {
                            if(value == '1'){
                                actions.push($.common.sprintf("<span class='%s'>%s</span>", "default","已确认"));
                            }
                            else {
                                actions.push($.common.sprintf("<span class='%s'>%s</span>", "default","未确认"));
                            }
                        }
                        return actions.join('');
                    }
                },
                {
                    field: 'updateBy',
                    title: '最后编辑人',
                },
                {
                    field: 'updateTime',
                    title: '最后保存时间',
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        //无权限
                        if(editFlag && editFlag == "hidden") {
                        }
                        else {
                            // if(row.isNewProgram == 1){
                            //     actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="edit(\'' + row.childId + "," + row.projectType +"," + row.isNewProgram + '\')"><i class="fa fa-edit"></i>标准计划编辑</a>');
                            // }
                            //当月临时生成项目的情况
                            // if(row.temShowEdit == 1){
                            //     actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="edit(\'' + row.childId + "," + row.projectType +"," + row.isNewProgram + '\')"><i class="fa fa-edit"></i>训练项目编辑</a>');
                            // } else {
                            //     //次月生成项目的情况
                            //     if (row.isShowEdit == 1) {
                            //         // if (row.threeDayBefore > 200 || row.threeDayBefore < 0) {
                            //         //     actions.push('<a class="btn btn-default btn-xs"  href="javascript:void(0)"><i class="fa fa-edit"></i>训练项目编辑</a>');
                            //         // } else {
                            //             actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="edit(\'' + row.childId + "," + row.projectType +"," + row.isNewProgram + '\')"><i class="fa fa-edit"></i>训练项目编辑</a>');
                            //         // }
                            //     }
                            // }

                        }
                        if (row.confirm == 0) {
                            actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="edit(\'' + row.childId + "," + row.projectType + "," + row.isNewProgram + '\')"><i class="fa fa-edit"></i>训练项目编辑</a>');
                        }else {
                            actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="checkProgram(\'' + row.childId+","+row.projectType+","+row.teacherName+ ","+row.isNewProgram+ '\')" ><i class="fa fa-edit"></i>训练项目查看</a>');
                        }
                        if (row.confirm == 1) {
                            actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="studentEntering(\'' + row.childId + "," + row.projectType + "," + row.trainingProgramNumber+ ","+row.centerId +'\')" style="margin-left: 10px"><i class="fa fa-edit"></i>成绩录入1</a>');
                        }
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });

    function edit(arr) {
        var data = arr.split(",");
        var scheduleTime = $('#scheduleTime').val();
        if(data[2] == 1){
            $.modal.openTab("训练项目编辑", prefix + "/newProgramEdit/"+data[0]+"/"+data[1]+"/"+scheduleTime+"/"+data[2]);
        }else {
            $.modal.openTab("训练项目编辑", prefix + "/edit/"+data[0]+"/"+data[1]+"/"+scheduleTime);
        }

        $.table.search();
    }

    function checkProgram(arr) {
        var data = arr.split(",");
        var scheduleTime = $('#scheduleTime').val();
        $.modal.openTab("训练项目查看", prefix + "/checkProgram/"+data[0]+"/"+data[1]+"/"+scheduleTime+"/"+data[2]+"/"+data[3]);
        $.table.search();
    }

    function studentEntering(data) {
        // console.log("1321564161651:",childId,projectType,trainingProgramNumber)
        var arr = data.split(",");
        var url = ctx + "education/childScheduleRecord/studentEntering/"+arr[0]+"/"+arr[1]+"/"+arr[2]+"/"+arr[3];
        $.modal.openTab("一对一成绩录入", url);
    }
    function queryParams(params) {
        var search = $.table.queryParams(params);
        var selectIndex = window.parent.document.getElementById('parentSchoolList').selectedIndex;
        if (selectIndex >= 0) {
            var centerId = window.parent.document.getElementById('parentSchoolList').options[selectIndex].value;
            search.centerId = centerId;
        }
        var scheduleTime = $('#scheduleTime').val();
        var teacherId = $('#teacherId').val();
        search.scheduleTime =scheduleTime;
        search.teacherId =teacherId;
        return search;
    }

</script>
</body>

</html>